import { deleteNovel } from '@/api/novel/novel';
import { ElMessage, ElMessageBox } from 'element-plus';

export default {
  data() {
    return {
      // ... existing data properties ...
    };
  },
  computed: {
    canManageNovel() {
      if (!this.userInfo || !this.novel) return false;
      if (this.novel.author_id === this.userInfo.id) return true;
      if (this.userInfo.role === 'admin' || this.userInfo.role === 'mod') return true;
      return false;
    }
  },
  methods: {
    async handleDeleteNovel() {
      if (!this.novel) return;
      
      try {
        await ElMessageBox.confirm(
          `确定要删除小说 "${this.novel.title}" 吗？此操作不可恢复。`,
          '删除小说',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }
        );

        const resp = await deleteNovel(this.novel.id);
        if (resp.error) {
          ElMessage({ type: 'error', message: resp.error });
          return;
        }

        ElMessage({ type: 'success', message: '小说已删除' });
        this.$router.push('/');
      } catch (e) {
        if (e !== 'cancel') {
          ElMessage({ type: 'error', message: '删除小说失败' });
        }
      }
    }
  }
};
</template>

<style scoped>
.danger-item {
  color: var(--el-color-danger);
}

.danger-item:hover {
  background-color: var(--el-color-danger-light-9);
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
</style> 